package gui;

import java.util.regex.Pattern;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;

@Named(value = "searchBean")
@RequestScoped
public class SearchBean {

    private String keyword;

    public SearchBean() {
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public String search() {
        if (keyword != null && !keyword.isEmpty() && Pattern.matches("[a-zA-Z0-9]*", keyword)) {
            return "searchResult?faces-redirect=true&keyword=" + keyword;
        }
        else {
            keyword = "";
            return "";
        }
    }
}
